package Month10.day1004;

public class First implements Cloneable{
    String name;
    int age;
    Second se;

    public First(String name, int age, Second se) {//第一个类的构造器
        this.name = name;
        this.age = age;
        this.se = se;
    }

    @Override
    public First clone() throws CloneNotSupportedException {//重写第一个类的clone方法
        First t1 = (First)super.clone();
        t1.se = se.clone();
        return t1;
    }

    @Override
    public String toString() {//重写toString方法，不然是一个地址值
        String s = "[";
        s += this.name + "," + this.age + "," + this.se + "]";
        return s;
    }

    public static void main(String[] args) throws CloneNotSupportedException {
        First f1 = new First("实验体一",1,new Second(new Third(1)));
        First f2 = f1.clone();
        f2.se.tir.num = 10;//修改第二个对象的值看会不会影响第一个对象
        System.out.println(f1);
        System.out.println(f2);
    }
}

